uniform sampler2D uni_sampler2D_gPosition;
uniform sampler2D uni_sampler2D_gNormal;
uniform sampler2D uni_sampler2D_gColor;
uniform sampler2D uni_sampler2D_gExt;
varying vec2 var_vec2_texcoord0;
varying vec3 var_vec3_farRay;

void main()
{
    float linearDepth=texture2D(uni_sampler2D_gPosition,var_vec2_texcoord0).x;
	vec3 nor=texture2D(uni_sampler2D_gNormal,var_vec2_texcoord0).xyz;
    vec3 pos=linearDepth*var_vec3_farRay;
	nor.z=sqrt(1.0f-nor.x*nor.x-nor.y*nor.y);
	
    vec3 lightPos=vec3(0,0,0);
    vec3 lightDir=normalize(lightPos-pos);
	float diff=max(0.0,dot(nor,lightDir));
	
	vec3 eyeDir=normalize(-pos);
	vec3 reLight=normalize(reflect(lightDir,nor));
	float spec=(pow(max(0.0,dot(reLight,-eyeDir)),50.0));
	
	vec4 color=texture2D(uni_sampler2D_gColor,var_vec2_texcoord0);
	gl_FragColor=color*diff+vec4(1.0,1.0,1.0,1.0)*spec;
	gl_FragColor.a=texture2D(uni_sampler2D_gExt,var_vec2_texcoord0).r;
}